package com.mes.defece.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.mes.common.pojo.MESResult;
import com.mes.defece.mapper.ShipmentMapper;
import com.mes.defece.service.ShipmentService;
import com.mes.pojo.defece.Shipment;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author 侯伟豪
 * @Company 起点编程
 * @Description
 * @Time 2024/10/24 19:45
 */
@Service
public class ShipmentServiceImpl implements ShipmentService {
    @Autowired
    private ShipmentMapper shipmentMapper;
    @Override
    public MESResult selectAll(Shipment shipment, Integer page, Integer limit) {
        PageHelper.startPage(page, limit);
        List<Shipment> shipments = shipmentMapper.selectAll(shipment);
        return MESResult.success(new PageInfo<>(shipments));
    }

    @Override
    public MESResult addShipment(Shipment shipment) {
        shipment.setShipmentStatus(1);
        return MESResult.isSuccess(shipmentMapper.insert(shipment));
    }

    @Override
    public MESResult selectById(Long shipmentId) {
        return MESResult.success(shipmentMapper.selectById(shipmentId));
    }

    @Override
    public MESResult updateShipmentById(Shipment shipment) {
        return MESResult.isSuccess(shipmentMapper.updateShipmentById(shipment));
    }

    @Override
    public MESResult deleteById(Long shipmentId) {
        Shipment shipment = new Shipment();
        shipment.setShipmentId(shipmentId);
        shipment.setShipmentStatus(99);
        return MESResult.success(shipmentMapper.deleteById(shipment));
    }
}